package cn.tedu.egmvc3.base.exception;

import cn.tedu.egmvc3.base.response.JsonResult;
import cn.tedu.egmvc3.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice     //等于 RestController + ExceptionHandler

public class GlobalExceptionHandle {
//    @ExceptionHandler
//    public JsonResult doHandleIllegalArgumentException(IllegalArgumentException ex){
//        String data = ex.getMessage();
//        log.error("doHandleIllegalArgumentException"+data);
//        return new JsonResult(StatusCode.OPERATION_FAILED,data);
//    }

    @ExceptionHandler
    public JsonResult doRuntimeException(RuntimeException er){
        String data = er.getMessage();
        log.error("doRuntimeException"+data);
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }

//    @ExceptionHandler
//    public JsonResult doHandleThrowable(Throwable ex){
//
//        String data = ex.getMessage();
//        log.error("doHandleThrowable"+data);
//        return new JsonResult(StatusCode.THROWABLE_ERROR,data);
//    }
}
